// 常用 Applicative 编程函数

var nums = [100, 2, 25];

function div(x, y) {
    return x / y;
}

var result = _.reduce(nums, div);
console.log("result:", result);

var resultRight = _.reduceRight(nums, div);
console.log("resultRight:", resultRight);

// 找到一个满足条件的就返回
var findResult = _.find(['a', 'b', 3, false, '10', 21.0], _.isNumber);
console.log("findResult:", findResult);

// 筛选所有满足条件的结果
var filterResult = _.filter(['a', 'b', 3, false, '10', 21.03], _.isNumber);
console.log("filterResult:", filterResult);

// 筛选所有不满足条件的结果，filter 取反
var rejectResult = _.reject(['a', 'b', 3, false, '10', 21.0], _.isNumber);
console.log("rejectResult:", rejectResult);

// 判断所有元素是否都满足条件，满足返回 true
// 只要有一个不满足条件，返回 false
var allResult = _.all([1, 2, 3, 4, 5], _.isNumber);
console.log("allResult:", allResult);

// 判断只要有一个元素满足条件就返回 true
// 所有元素都不满足条件才返回 fasle
var anyResult = _.any(['a', 'b', 'c', 'd'], _.isNumber);
console.log(["anyResult:", anyResult].join(" "));


// 排序相关的函数
var people = [
    {name: 'Nick', age: 30},
    {name: 'Jaka', age: 25},
    {name: 'Blue', age: 45}
];

var sortByResult = _.sortBy(people, function(p) { return p.age; });
console.log(sortByResult); 